package payment

import "sort"

// Processor 定义支付处理器接口
type Processor interface {
	Process(amount int) string
}

var registry = map[string]Processor{}

// Register 由各支付实现包内的 init() 调用
func Register(name string, p Processor) {
	registry[name] = p
}

// ListProcessors 返回已注册的处理器名称（有序）
func ListProcessors() []string {
	names := make([]string, 0, len(registry))
	for name := range registry {
		names = append(names, name)
	}
	sort.Strings(names)
	return names
}

// ProcessorByName 查询指定名称的处理器
func ProcessorByName(name string) (Processor, bool) {
	p, ok := registry[name]
	return p, ok
}
